/**
 *    @file       httptoolkit.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       01/16/2014 11:42:56 PM
 *
 *    @author     Theophilus (), wangtf418@gmail.com
 */
#ifndef _BF_HTTPTOOLKIT_H_
#define _BF_HTTPTOOLKIT_H_
#include <string>
#include <vector>
#include <list>
#include <map>
#include "comdef.h"
#include "netdef.h"
#include "toolkit.h"

//method line of http protocol
struct http_reqfirstline_t
{
	std::string m_method;
	std::string m_path;
	std::string m_version;
};

//request headers after method line
struct http_field_t
{
	std::string m_name;
	std::string m_value;
	http_field_t() {};
	http_field_t(const std::string &name, const std::string value)
		: m_name(name), m_value(value)
	{

	}
};

struct http_headfields_t
{
	std::map<std::string, http_field_t> m_reqheaders;
};

class httptoolkit
{
public:	
	httptoolkit();
	~httptoolkit();

public:
	static void url_encode(const std::string &str, std::string &str_out);
	static void url_decode(const std::string &str, std::string &str_out);
	static bf_int_t proc_http_header(const bf_char_t *head, bf_size_t headlen, http_reqfirstline_t &firstline, http_headfields_t &headfields);
	static std::string gen_http_header(const http_reqfirstline_t &firstline, const http_headfields_t &headfields);
public:
	static inline std::string get_http_statusstr(enum bf_http_status_code_t status_code)
	{
		const bf_char_t *status = BF_HTTP_STATUS_STR[status_code / 100 - 2][status_code % 100];
		return (status)? std::string(status):std::string(""); //impossible to return std::string("")
	}

};
#endif

